package swa2012.telco.client;

import java.net.URISyntaxException;
import java.util.Collection;
import java.util.List;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

import com.sun.jmx.snmp.Timestamp;

import swa2012.telco.broker.BrokerCallback;
import swa2012.telco.broker.beans.*;
import swa2012.telco.provider.ClientProvider;
import swa2012.telco.provider.TelcoProvider;
import swa2012.telco.provider.broker.BrokerCallbackImpl;

/**
 * @author kumar aberer
 * @date 10.06.2012
 */
public class TestClient {
	

	public static void main(String args[]) throws URISyntaxException {
		ClientProvider provider;
		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		factory.setServiceClass(ClientProvider.class);
		factory.setAddress("http://localhost:8012/SWA/Provider");
		provider = (ClientProvider) factory.create();
		

		
		Client kumar = provider.register("kumar");
		Client lukas = provider.register("lukas");
		
	
		Collection<Client> clients = provider.listClients();
	
		provider.sendMessage(new Message(lukas, kumar, "hey was geht", System.nanoTime()));
		
		
		System.out.println("------------------");
		for(Client c : clients)
			System.out.println(c.getID()+"@" + c.getProvider().getID());
		
		System.out.println();
		System.out.println("Kumars Inbox(remote):");
		System.out.println("------------------");
		System.out.println();
		Collection<Message> msgs = provider.getMessages(kumar.getID());
		if (msgs != null)
			for (Message m : msgs)
				System.out.println("(" + new Timestamp(m.getTimestamp()).getDate().toString() + ") " + m.getSender().getID() + ": " + m.getText());
	}
}
